﻿using Godot.core.os;

namespace Godot.core.io
{
    public class FileAccessPack : FileAccess
    {
        protected override Error _open(string p_path, int p_mode_flags)
        {
            throw new System.NotImplementedException();
        }

        protected override ulong _get_modified_time(string p_file)
        {
            throw new System.NotImplementedException();
        }

        public override void close()
        {
            throw new System.NotImplementedException();
        }

        public override void is_open()
        {
            throw new System.NotImplementedException();
        }

        public override void seek(uint p_position)
        {
            throw new System.NotImplementedException();
        }

        public override void seek_end(long p_position = 0)
        {
            throw new System.NotImplementedException();
        }

        public override uint get_pos()
        {
            throw new System.NotImplementedException();
        }

        public override uint get_len()
        {
            throw new System.NotImplementedException();
        }

        public override bool eof_reached()
        {
            return __eof;
        }

        public override Error get_error()
        {
            throw new System.NotImplementedException();
        }

        public override byte get_8()
        {
            if (__pos >= __pf.size)
            {
                __eof = true;
                return 0;
            }

            __pos++;
            return __f.get_8();
        }

        public override void store_8(byte p_dest)
        {
            throw new System.NotImplementedException();
        }

        public override bool file_exists(string p_name)
        {
            throw new System.NotImplementedException();
        }

        public FileAccessPack(string p_path, PackedData.PackedFile p_file) 
        {
	        __pf = p_file;
            Error err = Error.FAILED;
	        __f = FileAccess.open(__pf.pack, FileAccess.ModeFlags.READ, ref err);
	        if (null == __f) 
            {
		        //ERR_EXPLAIN("Can't open pack-referenced file: "+String(pf.pack));
                return;
	        }
	        __f.seek((uint)__pf.offset);
	        __pos = 0;
	        __eof = false;
        }

        private FileAccess __f;
        private PackedData.PackedFile __pf;
	    private uint __pos;
	    private bool __eof;

	    
    }
}
